<div class="content-section introduction">
    <div class="feature-intro">
        <h1>Tree <span>ContextMenu</span></h1>
        <p>Tree has exclusive integration with ContextMenu.</p>
    </div>
    <app-demoActions github="tree" stackblitz="treecontextmenu-demo"></app-demoActions>
</div>
<div class="content-section implementation">
    <div class="card">
        <p-tree [value]="files" selectionMode="single" [(selection)]="selectedFile" [contextMenu]="cm"></p-tree>
        
        <p-contextMenu #cm [model]="items"></p-contextMenu>
    <p-toast></p-toast>
    </div>
</div>

<div class="content-section documentation">
    <p-tabView>
        <p-tabPanel header="Source">
            <a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/tree" class="btn-viewsource" target="_blank">
                <span>View on GitHub</span>
            </a>
            <a href="https://stackblitz.com/edit/primeng-treecontextmenu-demo" class="btn-viewsource" style="margin-left: .5em;" target="_blank">
                <span>Edit in StackBlitz</span>
            </a>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-tree [value]="files" selectionMode="single" [(selection)]="selectedFile" [contextMenu]="cm"&gt;&lt;/p-tree&gt;

&lt;p-contextMenu #cm [model]="items"&gt;&lt;/p-contextMenu&gt;
&lt;p-toast&gt;&lt;/p-toast&gt;
</app-code>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;Component,OnInit&#125; from '@angular/core';
import &#123;NodeService&#125; from '../../service/nodeservice';
import &#123;MenuItem,TreeNode&#125; from 'primeng/api';
import &#123;MessageService&#125; from 'primeng/api';

@Component(&#123;
    templateUrl: './treecontextmenudemo.html',
    providers: [MessageService]
&#125;)
export class TreeContextMenuDemo implements OnInit &#123;

    files: TreeNode[];

    selectedFile: TreeNode;

    items: MenuItem[];
    
    constructor(private nodeService: NodeService, private messageService: MessageService) &#123; &#125;

    ngOnInit() &#123;
        this.nodeService.getFiles().then(files => this.files = files);

        this.items = [
            &#123;label: 'View', icon: 'pi pi-search', command: (event) => this.viewFile(this.selectedFile)&#125;,
            &#123;label: 'Unselect', icon: 'pi pi-times', command: (event) => this.unselectFile()&#125;
        ];
    &#125;

    viewFile(file: TreeNode) &#123;
        this.messageService.add(&#123;severity: 'info', summary: 'Node Details', detail: file.label&#125;);
    &#125;
    
    unselectFile() &#123;
        this.selectedFile = null;
    &#125;
&#125;
</app-code>   
        </p-tabPanel>
        <p-tabPanel header="StackBlitz">
            <ng-template pTemplate="content">
                <iframe src="https://stackblitz.com/edit/primeng-treecontextmenu-demo?embed=1" style="width: 100%; height: 768px; border: none;"></iframe>
            </ng-template>
        </p-tabPanel>
    </p-tabView>
</div>